package lc.q51_100;

public class Q65 {

    public boolean isNumber(String s) {
        if (s == null || s.equals("")) {
            return false;
        }
        s = s.toUpperCase();
        if (s.contains("E")) {
            int indexE = s.indexOf("E");
            String eNum = s.substring(indexE + 1);
            if (!checkInteger(eNum)){
                return false;
            }
            s = s.substring(0, indexE);
        }
        // 检测s是否为一个数
        // 如果符合正则num.num，那么就是
        if (s.contains(".")) {
            return s.matches("([+-]?)(\\d*)(\\.?)(\\d+)") || s.matches("([+-]?)(\\d+)(\\.?)(\\d*)");
        } else {
            return checkInteger(s);
        }
    }

    private boolean checkInteger(String s) {
        return s.matches("([+-]?\\d+)");
    }

    public static void main(String[] args) {
        Q65 x = new Q65();
        System.out.println(x.isNumber("+3.14"));
        System.out.println(x.isNumber("0089"));
        System.out.println(x.isNumber("-0.1"));
        System.out.println(x.isNumber("-90E3"));
        System.out.println(x.isNumber("+6e-1"));
        System.out.println(x.isNumber("-.9"));
        System.out.println(x.isNumber("99e2.5"));
        System.out.println(x.isNumber("e3"));
    }

}
